Skip to content

Implement firmware update functionality#153

Merged
syssi merged 8 commits intomasterfrom
add_updater
Feb 19, 2018
Merged

Implement firmware update functionality#153
syssi merged 8 commits intomasterfrom
add_updater

Conversation

@rytilahti
Copy link
Copy Markdown
Owner

@rytilahti rytilahti commented Jan 3, 2018

Add ability to perform firmware updates on the device.
Works either by passing an URL with md5sum for the firmware image,
or alternatively by passing a local filename.
In case of the input is a local filename, its md5sum will be calculated automatically,
and the update will be delivered by the built-in web server.

mirobo update_firmware http://10.10.10.150/v11_003094.pkg <md5sum>

or

mirobo update_firmware v11_003094.pkg

The install_sound functionality is also extended to use the builtin web-server class, so installing sound packages is as simple as calling mirobo install_sound <soundfile.pkg>.

For more details & archive of firmware updates see https://github.com/dgiese/dustcloud .

Thanks for exploring the device in-depth goes to the dustcloud project,
which also describes how to build own, custom firmwares.

click.echo("Using %s (md5: %s)" % (file, md5))
else:
pass
#Updater()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

block comment should start with '# '

miio/updater.py Outdated

if __name__ == "__main__":
import netifaces
ifaces_without_lo = [x for x in netifaces.interfaces() if not x.startswith("lo")]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (85 > 79 characters)

@coveralls
Copy link
Copy Markdown

coveralls commented Jan 3, 2018

Coverage Status

Coverage decreased (-1.9%) to 65.824% when pulling 791768f on add_updater into a365e17 on master.

self.server.timeout = 10

with open(file, 'rb') as f:
self.payload = f.read()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be memory inefficient

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it doesn't matter here, as the file needs to be read at some point for sending it to the client. The code is however incomplete, there is currently no way to tell interface/IP to use for the url (e.g. when one has multiple network interfaces as I do). I will have to look more into it in a week when I'll be able to test it on the device.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point i mean is you should read file by chunks and feed data to hash, reading hundreds megabytes to memory at once is a bad idea.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand what you mean, but at some the file has to be read (again) for sending over the wire to the device. I'll look into that though, thanks :-)

@CODeRUS
Copy link
Copy Markdown

CODeRUS commented Jan 6, 2018

btw, why own server? why handle_request so bad?

@rytilahti
Copy link
Copy Markdown
Owner Author

@CODeRUS I wanted to have it so that one can simply point it to any file (and not to expose the contents over HTTP), although I think changing to the source directory and launching the server there would be fine too.

Thanks for exploring the device in-depth goes to the dustcloud project,
which also describes how to build own, custom firmwares.
miio/updater.py Outdated
ifaces_without_lo = [x for x in netifaces.interfaces() if not x.startswith("lo")]
# print(ifaces_without_lo)
logging.basicConfig(level=logging.DEBUG)
upd = Updater("/tmp/test")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'Updater'

"""True if install is in progress."""
return self.sid != 0 and self.progress < 100 and self.error == 0
return self.state == SoundInstallState.Downloading or \
self.state == SoundInstallState.Installing
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent

try:
state = vac.update_state()
progress = vac.update_progress()
except: # we may not get our messages through during upload
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least two spaces before inline comment

if update_state == UpdateState.Downloading:
click.echo("Update progress: %s" % vac.update_progress())

@cli.command()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

click.echo("Configuring wifi to SSID: %s" % ssid)
click.echo(vac.configure_wifi(ssid, password, uid, timezone))

@cli.command()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

"""True if install is in progress."""
return self.sid != 0 and self.progress < 100 and self.error == 0
return self.state == SoundInstallState.Downloading or \
self.state == SoundInstallState.Installing
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent

try:
state = vac.update_state()
progress = vac.update_progress()
except: # we may not get our messages through during upload
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least two spaces before inline comment

if update_state == UpdateState.Downloading:
click.echo("Update progress: %s" % vac.update_progress())

@cli.command()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

click.echo("Configuring wifi to SSID: %s" % ssid)
click.echo(vac.configure_wifi(ssid, password, uid, timezone))

@cli.command()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

@rytilahti rytilahti changed the title WIP: Implement firmware update functionality Implement firmware update functionality Feb 17, 2018
@rytilahti
Copy link
Copy Markdown
Owner Author

I think this is pretty much done and ready to be tested now. The code could be made cleaner, but that can be done later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants